// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   CMPP30ConnectRepMessage.java

package com.haoxi.gateway.test.message;

import com.haoxi.gateway.test.CMPPConstant;
import com.haoxi.gateway.test.util.TypeConvert;
import com.haoxi.gateway.test.util.SecurityTools;

public class CMPP30ConnectRepMessage extends CMPPMessage {
    public CMPP30ConnectRepMessage(int sequenceID, int Status,
            String AuthenticatorSource, String shared_secret, int Version) {
        int len = 33;
        buf = new byte[len];
        TypeConvert.int2byte(len, buf, 0);
        TypeConvert.int2byte(CMPPConstant.Connect_Rep_Command_Id, buf, 4);
        setSequenceId(sequenceID);
        TypeConvert.int2byte(Status, buf, 12);
        if (shared_secret != null) {
            len = AuthenticatorSource.length() + 4 + shared_secret.length();
        } else {
            len = AuthenticatorSource.length() + 4;
        }
        byte tmpbuf[] = new byte[len];
        int tmploc = 0;
        // Status
        System.arraycopy(buf, 12, tmpbuf, 0, 4);
        // AuthenticatorSource
        System.arraycopy(AuthenticatorSource.getBytes(), 0, tmpbuf, 4,
                AuthenticatorSource.length());

        tmploc = AuthenticatorSource.length();
        // shared_secret
        if (shared_secret != null) {
            System.arraycopy(shared_secret.getBytes(), 0, tmpbuf, tmploc + 4,
                    shared_secret.length());
        }
        SecurityTools.md5(tmpbuf, 0, len, buf, 16);
        buf[32] = (byte) Version;

    }

    public int getMessageLength() {
        return TypeConvert.byte2int(buf, 0);
    }

    public int getCommandId() {
        return TypeConvert.byte2int(buf, 4);
    }

    public int getStatus() {
        return TypeConvert.byte2int(buf, 12);
    }

    public byte[] getAuthenticatorISMG() {
        byte tmpbuf[] = new byte[16];
        System.arraycopy(buf, 16, tmpbuf, 0, 16);
        return tmpbuf;
    }

    public byte getVersion() {
        return buf[32];
    }

    public String toString() {
        String tmpStr = "CMPP_Connect_REP: ";
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nMessageLength=")
                .append(getMessageLength())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nCommid=")
                .append(getCommandId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nSequence_Id=")
                .append(getSequenceId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nStatus=")
                .append(getStatus())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append(
                "\r\nAuthenticatorISMG=").append(
                new String(getAuthenticatorISMG()))));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nVersion=")
                .append(getVersion())));
        return tmpStr;
    }
}
